package giab.weixin.web.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

@Repository
public class SystemSessionInterceptor extends HandlerInterceptorAdapter {

	private static Logger logger = LoggerFactory
			.getLogger(SystemSessionInterceptor.class);

	@Override
	public void postHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		// TODO Auto-generated method stub
//		request.setCharacterEncoding("UTF-8");
//		response.setCharacterEncoding("UTF-8");
//		response.setContentType("text/html;charset=UTF-8");
//		Object obj = request.getSession().getAttribute("user");
//		// if(obj==null){
//		// modelAndView.clear();
//		// modelAndView.addObject(new RedirectView("forward:/defaultError"));
//		// }
//		logger.debug("过滤显示");

		super.postHandle(request, response, handler, modelAndView);
	}

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		// TODO Auto-generated method stub
//		request.setCharacterEncoding("UTF-8");
//		response.setCharacterEncoding("UTF-8");
//		response.setContentType("text/html;charset=UTF-8");
//		System.out.println(request.getRequestURI().toString());
//		String url = request.getRequestURL().toString();
//
//		if (url.contains("rror"))
//			return true;
//		Object obj = request.getSession().getAttribute("user");
//		if (obj == null) {
//			request.getRequestDispatcher("defaultError").forward(request,
//					response);
//			return false;
//		}

		return super.preHandle(request, response, handler);
	}

}
